package com.Interlend.implement.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.json.JSONObject;
import org.osoa.sca.annotations.Service;

import com.Interlend.interfaces.User.UserRegister;
import com.Interlend.utils.InterlendDBToolkit;

@Service(UserRegister.class)
public class UserRegisterImpl implements UserRegister{

	@Override
	public String execute(String username, String password, int sid,
			String snum, String email, int isValiable) {
		Connection connection = InterlendDBToolkit.getConnection();
		String sql = "insert into user(username,password,sid,snum,email,isValiable) values (?,?,?,?,?,?)";
        PreparedStatement psmt=null; 
        JSONObject jsonObject = new JSONObject();
        
        try {
			psmt = connection.prepareStatement(sql);
			psmt.setString(1, username);
			psmt.setString(2, password);
			psmt.setInt(3, sid);
			psmt.setString(4, snum);
			psmt.setString(5, email);
			psmt.setInt(6, isValiable);
			psmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
			jsonObject.put("exception", "1");
			jsonObject.put("result", "-1");
			return jsonObject.toString();
		}

		jsonObject.put("exception", "0");
		jsonObject.put("result", "1");
		return jsonObject.toString();
	}
}
